package com.indigon.turing.control
{
	import com.indigon.turing.data.ArenaData;
	import com.indigon.turing.model.Model;
	import com.indigon.turing.view.Renderer;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.utils.Timer;

	public class Control
	{
		public static const UPDATES_PER_SECOND : uint = 10;
		
		private var _lastMouseCoords : Point;
		
		private var _timer : Timer;
		private var _model : Model;
		private var _view  : Renderer;
		
		public function Control()
		{
			_model = new Model();
			_view  = new Renderer(_model);
			
			_timer = new Timer(Math.floor(1000 / UPDATES_PER_SECOND), 0);
		}
		
		public function reset():void
		{
			_model.reset();
			_view.reset();
		}
		
		public function configure(data:ArenaData):void
		{
			_model.configure(data);
			_view.configure(data);
		}
		
		public function start():void
		{
			_timer.addEventListener(TimerEvent.TIMER, update);
			_timer.start();
		}
		
		public function stop():void
		{
			_timer.removeEventListener(TimerEvent.TIMER, update);
			_timer.stop();
		}
		
		private function update(e:Event):void
		{
			_model.update();
			_view.update();
		}
		
		public function get canvas():DisplayObject
		{
			return _view;
		}
	}
}